using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Entity;
using System.Data;
namespace DAL
{
    public class BaseInfoDAL
    {
        /// <summary>
        /// 配置单件实例
        /// </summary>
        public static readonly BaseInfoDAL Instance = new BaseInfoDAL();

        /// <summary>
        /// 获取网站基本信息表数据个数
        /// </summary>
        /// <returns></returns>
        public int GetBaseInfoCount()
        {
            return int.Parse(SqlHelper.ExecuteDataSet("select count(id) from base_info ").Tables[0].Rows[0][0].ToString());
        }
        /// <summary>
        /// 获取网站基本信息表数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetBaseInfo()
        {
            return SqlHelper.ExecuteDataSet("select *  from base_info ").Tables[0];
        }

        /// <summary>
        /// 保存基本信息数据
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public bool InsertBaseInfo(string[] values)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                if (GetBaseInfoCount() > 0)
                {
                    sb.Append("update base_info set  ");
                    sb.Append("title='" + values[0] + "'");
                    sb.Append(",keys='" + values[1] + "'");
                    sb.Append(",base_info='" + values[2] + "'");
                    sb.Append(",phone='" + values[3] + "'");
                    if (values[4].Trim() != "")
                    {
                        sb.Append(",logopath='" + values[4] + "'");
                    }
                    sb.Append(",bottom_info='" + values[5] + "'");
                    sb.Append(",smtp='" + values[6] + "'");
                    sb.Append(",email='" + values[7] + "'");
                    sb.Append(",password='" + values[8] + "'");
                    sb.Append(",money_name='" + values[9] + "'");
                    sb.Append(",money=" + values[10] );
                    sb.Append(",is_close='" + values[11] + "'");
                    sb.Append(",admin_account='" + values[12] + "'");
                }
                else
                {
                    sb.Append(" insert into base_info(title,keys,base_info,phone,logopath,bottom_info,smtp,email,password,money_name,money,is_close,admin_account) values (");
                     sb.Append("'" + values[0] );
                    sb.Append("','" + values[1] );
                    sb.Append("','" + values[2] );
                    sb.Append("','" + values[3] );
                    sb.Append("','" + values[4] );
                    sb.Append("','" + values[5] );
                    sb.Append("','" + values[6] );
                    sb.Append("','" + values[7] );
                    sb.Append("','" + values[8] );
                    sb.Append("','" + values[9] );
                    sb.Append("'," + values[10] );
                    sb.Append(",'" + values[11] );
                    sb.Append("','" + values[12]  +"')");
                }
                if (SqlHelper.ExecuteNonQuery(sb.ToString(), null) > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ee)
            {
            }
            return true;
        }
    }
}
